import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:ichinesereader/constants.dart';
import 'package:ichinesereader/controller/reports.dart';
import 'package:ichinesereader/pages/assessment/assessmentBooksRecords.dart';
// import 'package:ichinesereader/pages/student/SkillBuildingRecords.dart';
import 'package:ichinesereader/pages/student/homeworkRecords.dart';
import 'package:ichinesereader/pages/student/basket.dart';
import 'package:ichinesereader/pages/student/readingRecords.dart';
import 'package:ichinesereader/routes/routePages.dart';
import 'package:ichinesereader/themes/pageStyles.dart';
import 'package:ichinesereader/utils/log.dart';
import 'package:ichinesereader/widgets/layouts/appdrawerStudent.dart';
import 'package:ichinesereader/widgets/layouts/customAppBar.dart';
import 'package:ichinesereader/widgets/sidebars/studentSidebar.dart';
import '../../themes/appTheme.dart';

class StudentReportsPage extends StatefulWidget {
  static const String routeName = '/student/reports';

  @override
  State<StudentReportsPage> createState() => _StudentReportsPageState();
}

class _StudentReportsPageState extends State<StudentReportsPage> {
  final box = Hive.box('appconfig');

  @override
  void initState() {
    Get.put(ReportsController());
    super.initState();
  }

  @override
  void dispose() {
    // not delete it, otherwise redscreen when go to assessment report
    //Get.delete<ReportsController>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    Log.debug('build StudentReportsPage');
    // bool isStudent = box.get(CacheManagerKey['nanhairole'].toString()) ==
    //     Constants.NanhaiRole_Student;
    final PageStyles _pageStyles = PageStyles();
    final isSmallScreen =
        MediaQuery.of(context).size.width < Constants.DefinedScreenSmallSize;
    final isBigScreen =
        MediaQuery.of(context).size.width > Constants.DefinedScreenBigSize;
    int _selectedSidebarItem = RoutePages.studentPageItems
        .indexWhere((page) => page.route == Get.currentRoute);

    return DefaultTabController(
      length: 4,
      child: Scaffold(
        appBar: isSmallScreen ? CustomAppBar(title: 'Reports'.tr) : null,
        drawer: isSmallScreen ? StudentAppDrawer() : null,
        body: Container(
          decoration: _pageStyles.pageBoxDecoration(),
          child: Row(
            children: [
              Visibility(
                  visible: !isSmallScreen,
                  child: StudentSidebarX(
                      selectedIndex: _selectedSidebarItem,
                      isBigScreen: isBigScreen)),
              Expanded(
                flex: 10,
                child: Container(
                  margin: _pageStyles.mainContainerPageEdgeInsets(),
                  child: Column(
                    children: [
                      Container(
                        padding: EdgeInsets.symmetric(vertical: 9.0),
                        decoration: BoxDecoration(
                          color: Get.isDarkMode
                              ? AppTheme.colors.darkTheme2
                              : Colors.black.withOpacity(0.1),
                          borderRadius: BorderRadius.circular(3.0),
                        ),
                        child: _pageStyles.buildTabBar([
                          'Recent Read'.tr,
                          'Basket'.tr,
                          'Homework'.tr,
                          'Quiz Books'.tr,
                          // 'Skill Building'.tr
                        ]),
                      ),
                      Expanded(
                        flex: 11,
                        child: Padding(
                          padding: const EdgeInsets.only(top: 12.0),
                          child: TabBarView(
                            children: [
                              LatestReadingRecords(),
                              StudentBasketsPage(),
                              MyHomeworkRecords(),
                              AssessmentBookRecords(),
                              // SkillBuildingRecords()
                            ],
                          ),
                        ),
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
